package com.zjl.redis.第01章_redis安装;

import redis.clients.jedis.*;

/**
 * ClassName: RedisUtil
 * Package: com.zjl.spring6.redis.第一章redis安装
 * Description:
 *
 * @Author 张蛟龙
 * @Create 2024/6/22 17:13
 * @Version 1.0
 */
public class RedisUtil {
    public static Jedis jedis = null;
    public static Jedis getRedis() {
        if(jedis == null){

            DefaultJedisClientConfig.Builder builder = DefaultJedisClientConfig.builder();//创建一个设置参数的类

            JedisClientConfig redisConfig = builder.password("er485g96er8").build();//设置密码

            jedis = new Jedis("82.157.71.243", 6379, redisConfig);//连接Redis
        }
        return jedis;
    }
    public static JedisPool jedisPool = null;
    public static Jedis getRedisPool() {
        if(jedisPool == null){
            DefaultJedisClientConfig.Builder builder = DefaultJedisClientConfig.builder();//创建一个设置参数的类
            JedisClientConfig redisConfig = builder.password("er485g96er8").build();//设置密码
            HostAndPort hostAndPort = new HostAndPort("82.157.71.243", 6379);
            jedisPool = new JedisPool(hostAndPort,redisConfig);
        }
        return jedisPool.getResource();
    }
}
